﻿using System;

namespace SmlEngine.IO.Uri
{
    /// <summary>
    /// Represents a Uri with advanced support for relative paths.
    /// </summary>
    public class AdvancedUri
    {
        /// <summary>
        /// Gets or sets the the AdvancedUriKind of the AdvancedUri.
        /// </summary>
        public AdvancedUriKind UriKind { get; set; }

        /// <summary>
        /// Gets or sets the file path or the AdvancedUri.
        /// </summary>
        public string Path { get; set; }

        /// <summary>
        /// Gets the path of the AdvancedUri, beginning with the identifier
        /// </summary>
        public string IdentifiedPath
        {
            get
            {
                return AdvancedUriHelper.GetIdentifier(UriKind) + Path;
            }
        }

        /// <summary>
        /// Constructs a new AdvancedUri from the specified path.
        /// </summary>
        /// <param name="path">The file path or the AdvancedUri.</param>
        public AdvancedUri(string path)
        {
            if (AdvancedUriHelper.HasIdentifier(path))
            {
                UriKind = AdvancedUriHelper.RetrieveUriType(path);
                Path = AdvancedUriHelper.RemoveIdentifier(path);
            }
            else
            {
                UriKind = AdvancedUriKind.Indeterminate;
                Path = path;
            }
        }

        /// <summary>
        /// Constructs a new AdvancedUri from the specified path and AdvancedUriKind.
        /// </summary>
        /// <param name="path">The file path or the AdvancedUri.</param>
        /// <param name="uriKind">The AdvancedUriKind of the AdvancedUri.</param>
        public AdvancedUri(string path, AdvancedUriKind uriKind)
        {
            Path = path;
            UriKind = uriKind;
        }
    }
}
